//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.jeeplus.modules.gen.web;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Maps;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.utils.PropertiesLoader;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.gen.Creak;
import com.jeeplus.modules.gen.entity.GenConfig;
import com.jeeplus.modules.gen.entity.GenCustomObj;
import com.jeeplus.modules.gen.entity.GenDict;
import com.jeeplus.modules.gen.entity.GenScheme;
import com.jeeplus.modules.gen.entity.GenTable;
import com.jeeplus.modules.gen.entity.GenTableColumn;
import com.jeeplus.modules.gen.entity.GenTemplate;
import com.jeeplus.modules.gen.mapper.GenDataBaseDictMapper;
import com.jeeplus.modules.gen.mapper.GenTableColumnMapper;
import com.jeeplus.modules.gen.mapper.GenTableMapper;
import com.jeeplus.modules.gen.mapper.GenTemplateMapper;
import com.jeeplus.modules.gen.service.GenCustomObjService;
import com.jeeplus.modules.gen.service.GenSchemeService;
import com.jeeplus.modules.gen.service.GenTableService;
import com.jeeplus.modules.gen.service.GenTemplateService;
import com.jeeplus.modules.gen.template.FreemarkerHelper;
import com.jeeplus.modules.gen.util.a;
import com.jeeplus.modules.gen.util.d;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.UserUtils;

@Controller
@RequestMapping({"${adminPath}/gen/genTable"})
public class GenTableController extends BaseController {
    @Autowired
    public GenTemplateService genTemplateService;
    @Autowired
    public GenTableService genTableService;
    @Autowired
    private GenTableMapper genTableMapper;
    @Autowired
    public GenSchemeService genSchemeService;
    @Autowired
    public GenTemplateMapper genTemplateMapper;
    @Autowired
    private GenTableColumnMapper genTableColumnMapper;
    @Autowired
    private GenDataBaseDictMapper genDataBaseDictMapper;
    @Autowired
    private GenCustomObjService genCustomObjService;
    private static String b = "200";
    private static String b1 = "h";
    private static String b2 = "t";
    private static String b3 = "p";
    private static String b4 = "80";
    private static String b5 = "/";
    private static String c = "197";
    private static PropertiesLoader a6 = new PropertiesLoader(new String[]{"/properties/license.properties"});
    private Map<String, String> a8 = Maps.newHashMap();
    private static String d = "196";
    private static String d1 = "http://v.jeeplus.org/a";
    private static final String a7;
    private static final String a9;

    static {
        a7 = d1 + "/auth/jeeplusUser/getGenTemplate?";
        a9 = d1 + "/auth/jeeplusUser/initGenTemplate?";
    }

    public GenTableController() {
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.setAutoGrowCollectionLimit(1024);
    }

    private static String a1(String a1) throws Exception {
        URL a2 = new URL(a1);
        HttpURLConnection a3 = (HttpURLConnection)a2.openConnection();
        a3.setRequestMethod("POST");
        a3.setRequestProperty("Content-type", "text/html");
        a3.setRequestProperty("Accept-Charset", "utf-8");
        a3.setRequestProperty("contentType", "utf-8");
        a3.setConnectTimeout(3000);
        a3.setReadTimeout(3000);
        a3.connect();
        InputStream a4 = a3.getInputStream();
        InputStreamReader a5 = new InputStreamReader(a4, "UTF-8");
        BufferedReader a6 = new BufferedReader(a5);
        String a7 = null;
        StringBuffer a8 = new StringBuffer();

        while((a7 = a6.readLine()) != null) {
            a8.append(a7);
        }

        a5.close();
        a3.disconnect();
        return a8.toString();
    }

    private String a2(String a1, String a2, String a3, String a4, String a5, String a6) {
        if(a3 == null || "".equals(a3) || a3.startsWith("输入错误")) {
            a3 = a4;
        }

        String a7 = "1";

        try {
            a7 = a1(a9 + "mac=" + a7(a3, "UTF-8") + "&productID=" + a1 + "&license=" + a2 + "&ip=" + a7(a4, "UTF-8") + "&type=" + a7(a5, "UTF-8") + "&version=" + a7(a6, "UTF-8") + "&inittime=" + a7(a.a12(), "UTF-8"));
        } catch (Exception var9) {
            var9.printStackTrace();
        }

        return a7;
    }

    private GenTemplate a3(String a4, String a1, String a2) {
        if(a4 == null || "".equals(a4) || a4.startsWith("输入错误")) {
            a4 = a2;
        }

        GenTemplate a3 = new GenTemplate();

        try {
            String var6 = a1(a7 + "mac=" + a7(a4, "UTF-8") + "&productID=" + a7(a1, "UTF-8"));
            a3.setName(var6);
        } catch (Exception var61) {
            a3.setName("-2");
        }

        return a3;
    }

    private static String a7(String a1, String a2) throws UnsupportedEncodingException {
        if(a1 == null) {
            a1 = "";
        }

        return URLEncoder.encode(a1, "UTF-8");
    }

    private String a7(String a1) {
        String a2 = (String)this.a8.get(a1);
        if(a2 == null) {
            a2 = a6.getProperty(a1);
            this.a8.put(a1, a2 != null?a2:"");
        }

        return a2;
    }

    public GenTable a0(GenTable a1) {
        return StringUtils.isNotBlank(a1.getId())?this.genTableService.a1(a1.getId()):a1;
    }

    @RequiresPermissions({"gen:genTable:list"})
    @RequestMapping({"list", ""})
    public String a11(GenTable genTable, HttpServletRequest request, HttpServletResponse response, Model model) throws IOException, d {
        Creak.k();

        try {
            String var13 = this.a7("productID");
            String a2 = this.a7("license");
            String a3 = a.a1();
            HashMap a4 = new HashMap();
            a4.put("serial", a3);
            PrintWriter a5;
            if(a2 != null && !a2.equals("")) {
                if(!a.b1(a2).equals(a3) && !Creak.kill) {
                    response.reset();
                    response.setContentType("text/html;charset=UTF-8");
                    response.setHeader("Cache-Control", "no-store");
                    a5 = response.getWriter();
                    a5.write((new FreemarkerHelper()).parseTemplate("com/jeeplus/modules/gen/web/lock.ftl", a4));
                    a5.flush();
                    return null;
                } else {
                    if(Creak.kill) {
                        request.getSession().setAttribute("template", (Object)null);
                    }

                    GenTemplate a51;
                    if(request.getSession().getAttribute("template") == null) {
                        a51 = this.a3(a.f1, var13, request.getLocalAddr());
                        GenTemplate pw1 = this.genTemplateService.a2("0");
                        if(pw1 == null) {
                            pw1 = new GenTemplate();
                            pw1.setId("0");
                            pw1.setIsNewRecord(true);
                            pw1.setName("0");
                            this.genTemplateMapper.insert(pw1);
                        }

                        if(!a51.getName().equals("-2")) {
                            if(Creak.kill) {
                                a51.setName("-1");
                            }

                            if(a51.getName().equals("-1")) {
                                this.a2(var13, a2, a.f1, request.getLocalAddr(), a.a1, a.a2);
                            } else {
                                try {
                                    MyBeanUtils.copyBeanNotNull2Bean(a51, pw1);
                                    this.genTemplateService.a1(pw1);
                                } catch (Exception var131) {
                                    ;
                                }
                            }
                        }

                        request.getSession().setAttribute("template", pw1);
                    } else {
                        a51 = (GenTemplate)request.getSession().getAttribute("template");
                    }

                    if(a51.getName().equals("1")) {
                        response.reset();
                        response.setContentType("text/html;charset=UTF-8");
                        response.setHeader("Cache-Control", "no-store");
                        PrintWriter pw11 = response.getWriter();
                        pw11.write((new FreemarkerHelper()).parseTemplate("com/jeeplus/modules/gen/web/lock.ftl", a4));
                        pw11.flush();
                        return null;
                    } else {
                        return "modules/gen/genTableList";
                    }
                }
            } else {
                response.reset();
                response.setContentType("text/html;charset=UTF-8");
                response.setHeader("Cache-Control", "no-store");
                a5 = response.getWriter();
                a5.write((new FreemarkerHelper()).parseTemplate("com/jeeplus/modules/gen/web/valid.ftl", a4));
                a5.flush();
                return null;
            }
        } catch (IOException var14) {
            throw new d(var14.toString(), var14);
        }
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:list"})
    @RequestMapping({"data"})
    public Map<String, Object> a(GenTable b2, HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
        b2 = this.a0(b2);
        User a1 = UserUtils.getUser();
        if(!a1.isAdmin()) {
            b2.setCreateBy(a1);
        }

        Page a6 = this.genTableService.a2(new Page(request, response), b2);
        return this.getBootstrapData(a6);
    }

    @RequiresPermissions(
        value = {"gen:genTable:view", "gen:genTable:add", "gen:genTable:edit"},
        logical = Logical.OR
    )
    @RequestMapping({"form"})
    public String a(GenTable c1, HttpServletResponse response, Model model,HttpServletRequest request) throws IOException {
    	
    	
    	System.out.println(request.getParameter("act"));
        Creak.k();
        String a1 = this.a7("productID");
        String a2 = this.a7("license");
        String a3 = a.a1();
        HashMap a4 = new HashMap();
        a4.put("serial", a3);
        PrintWriter f;
        if(a2 != null && !a2.equals("")) {
            if(!a.b1(a2).equals(a3) && !Creak.kill) {
                response.reset();
                response.setContentType("text/html;charset=UTF-8");
                response.setHeader("Cache-Control", "no-store");
                f = response.getWriter();
                f.write((new FreemarkerHelper()).parseTemplate("com/jeeplus/modules/gen/web/lock.ftl", a4));
                f.flush();
                return null;
            } else {
                c1 = this.a0(c1);
                model.addAttribute("genTable", c1);
                List f1 = this.genCustomObjService.findList(new GenCustomObj());
                GenConfig f2 = a.a7();
                Iterator var10 = f1.iterator();

                while(var10.hasNext()) {
                    GenCustomObj genObj = (GenCustomObj)var10.next();
                    GenDict f11 = new GenDict();
                    f11.setLabel(genObj.getLabel());
                    f11.setValue(genObj.getValue());
                    f11.setDescription(genObj.getRemarks());
                    f2.getJavaTypeList().add(f11);
                }

                model.addAttribute("config", f2);
                model.addAttribute("act", request.getParameter("act")==null?0:Integer.valueOf(request.getParameter("act")));
                model.addAttribute("tableList", this.genTableService.a3());
                return "modules/gen/genTableForm";
            }
        } else {
            response.reset();
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Cache-Control", "no-store");
            f = response.getWriter();
            f.write((new FreemarkerHelper()).parseTemplate("com/jeeplus/modules/gen/web/valid.ftl", a4));
            f.flush();
            return null;
        }
    }

    @ResponseBody
    @RequiresPermissions(
        value = {"gen:genTable:add", "gen:genTable:edit"},
        logical = Logical.OR
    )
    @RequestMapping({"save"})
    public AjaxJson a4(GenTable a2, Model model, RedirectAttributes redirectAttributes, HttpServletResponse response) throws IOException {
        GenTable a1 = this.a0(a2);
        a2.setOldComments(a1.getOldComments());
        a2.setOldName(a1.getOldName());
        a2.setOldGenIdType(a1.getOldGenIdType());
        AjaxJson j = new AjaxJson();
        if(!this.beanValidator(model, a2, new Class[0])) {
            j.setSuccess(false);
            j.setMsg("参数错误！");
            return j;
        } else if(StringUtils.isBlank(a2.getId()) && !this.genTableService.a5(a2.getName())) {
            j.setSuccess(false);
            j.setMsg("添加失败！" + a2.getName() + " 记录已存在！");
            return j;
        } else if(StringUtils.isBlank(a2.getId()) && !this.genTableService.a7(a2.getName())) {
            j.setSuccess(false);
            j.setMsg("添加失败！" + a2.getName() + "表已经在数据库中存在,请从数据库导入表单！");
            return j;
        } else if(StringUtils.isNotBlank(a2.getId()) && !a2.getName().equals(a1.getName()) && !this.genTableService.a5(a2.getName())) {
            j.setSuccess(false);
            j.setMsg("重命名失败！" + a2.getName() + " 记录已存在！");
            return j;
        } else if(StringUtils.isNotBlank(a2.getId()) && !a2.getName().equals(a1.getName()) && !this.genTableService.a7(a2.getName())) {
            j.setSuccess(false);
            j.setMsg("重命名失败！" + a2.getName() + "表已经在数据库中存在,请从数据库导入表单！");
            return j;
        } else {
            List a4 = a2.getColumnList();
            Iterator var8 = a4.iterator();

            while(var8.hasNext()) {
                GenTableColumn a5 = (GenTableColumn)var8.next();
                GenCustomObj a6;
                if("gridselect".equals(a5.getShowType())) {
                    if(!"This".equals(a5.getJavaType())) {
                        a6 = (GenCustomObj)this.genCustomObjService.findUniqueByProperty("value", a5.getJavaType());
                        if(a6 == null) {
                            j.setSuccess(false);
                            j.setMsg(a5.getJavaField() + "字段对应的显示表单类型你选择了【gridselect】或者【树选择控件】，<br/>但是对应的java类型你没有关联自定义java对象！<br/>");
                            return j;
                        }

                        a5.setDataUrl(a6.getDataUrl());
                        a5.setTableName(a6.getTableName());
                    }
                } else if("treeselect".equals(a5.getShowType()) && !"This".equals(a5.getJavaType()) && !a5.getName().equals(a2.getParentTableFk())) {
                    a6 = (GenCustomObj)this.genCustomObjService.findUniqueByProperty("value", a5.getJavaType());
                    if(a6 == null) {
                        j.setSuccess(false);
                        j.setMsg(a5.getJavaField() + "字段对应的显示表单类型你选择了【gridselect】或者【树选择控件】，<br/>但是对应的java类型你没有关联自定义java对象！<br/>");
                        return j;
                    }

                    a5.setDataUrl(a6.getDataUrl());
                    a5.setTableName(a6.getTableName());
                }
            }

            if(StringUtils.isNotBlank(a2.getOldName()) && !this.genTableService.a7(a2.getOldName())) {
                this.genTableService.b2(a2);
            } else {
                this.genTableService.b1(a2);
            }

            j.setSuccess(true);
            j.setMsg("保存业务表\'" + a2.getName() + "\'成功");
            return j;
        }
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:importDb"})
    @RequestMapping({"saveTableFromDB"})
    public AjaxJson a3(String name, Model model, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        StringBuffer a1 = new StringBuffer();
        String[] a2 = name.split(",");
        String[] var7 = a2;
        int var8 = a2.length;

        for(int var9 = 0; var9 < var8; ++var9) {
            String a = var7[var9];
            if(StringUtils.isNotBlank(a)) {
                if(!this.genTableService.a5(a)) {
                    a1.append("<font color=\'red\'>数据库导入表单" + a + " 失败，表已经添加!</font><br/>");
                } else {
                    GenTable a3 = new GenTable();
                    a3.setName(a);
                    a3 = this.genTableService.a5(a3);
                    a3.setTableType("0");
                    this.genTableService.d(a3);
                    a1.append("<font color=\'green\'>数据库导入表单\'" + a3.getName() + "\'成功!</font><br/>");
                }
            }
        }

        j.setSuccess(true);
        j.setMsg(a1.toString());
        return j;
    }

    @RequiresPermissions({"gen:genTable:importDb"})
    @RequestMapping({"importTableFromDB"})
    public String a1(GenTable genTable, Model model, RedirectAttributes redirectAttributes) {
        return "modules/gen/importTableFromDB";
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:importDb"})
    @RequestMapping({"importTableData"})
    public Map<String, Object> a(GenTable genTable, Model model, RedirectAttributes redirectAttributes) {
        List a = this.genTableService.a4(genTable);
        HashMap x = new HashMap();
        x.put("rows", a);
        x.put("total", Integer.valueOf(a.size()));
        return x;
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:del"})
    @RequestMapping({"delete"})
    public AjaxJson a2(GenTable genTable, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        genTable = this.a0(genTable);
        this.genTableService.e(genTable);
        this.genSchemeService.a5(this.genSchemeService.b1("gen_table_id", genTable.getId()));
        j.setSuccess(true);
        j.setMsg("移除业务表记录成功");
        return j;
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:del"})
    @RequestMapping({"deleteDb"})
    public AjaxJson a1(GenTable x, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        if(Global.isDemoMode().booleanValue()) {
            j.setSuccess(false);
            j.setMsg("演示模式，不允许操作！");
            return j;
        } else {
            x = this.a0(x);
            this.genTableService.e(x);
            this.genSchemeService.a5(this.genSchemeService.b1("gen_table_id", x.getId()));
            StringBuffer y = new StringBuffer();
            String c = Global.getConfig("jdbc.type");
            if("mysql".equals(c)) {
                y.append("drop table if exists " + x.getName() + " ;");
            } else if("oracle".equals(c)) {
                try {
                    y.append("DROP TABLE " + x.getName());
                } catch (Exception var7) {
                    ;
                }
            } else if("mssql".equals(c) || "sqlserver".equals(c)) {
                y.append("if exists (select * from sysobjects where id = object_id(N\'[" + x.getName() + "]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1)  drop table [" + x.getName() + "]");
            }

            this.genTableService.f(y.toString());
            j.setSuccess(true);
            j.setMsg("删除业务表记录和数据库表成功!");
            return j;
        }
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:del"})
    @RequestMapping({"deleteAll"})
    public AjaxJson b3(String ids, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        String[] idArray = ids.split(",");
        String[] var5 = idArray;
        int var6 = idArray.length;

        for(int var7 = 0; var7 < var6; ++var7) {
            String id = var5[var7];
            this.genTableService.e(this.genTableService.a1(id));
        }

        j.setSuccess(true);
        j.setMsg("移除业务表成功!");
        return j;
    }

    @ResponseBody
    @RequiresPermissions({"gen:genTable:synchDb"})
    @RequestMapping({"synchDb"})
    public AjaxJson a4(GenTable a4, String isForce, RedirectAttributes redirectAttributes) {
        AjaxJson j = new AjaxJson();
        if(Global.isDemoMode().booleanValue()) {
            j.setSuccess(false);
            j.setMsg("演示模式，不允许操作！");
            return j;
        } else {
            String a1 = Global.getConfig("jdbc.type");
            a4 = this.a0(a4);
            List a2 = a4.getColumnList();
            List a3 = a4.getAllColumnList();
            StringBuffer a11;
            String pk2;
            String c11;
            if("mysql".equals(a1)) {
                GenTable b42;
                String column2;
                Iterator column;
                GenTableColumn c1;
                String c2;
                if("1".equals(isForce) && a4.getOldName() != null) {
                    a11 = new StringBuffer();
                    if(!a4.getName().equalsIgnoreCase(a4.getOldName())) {
                        a11.append("ALTER  TABLE " + a4.getOldName() + " RENAME TO " + a4.getName() + ";");
                        this.genTableService.f("ALTER  TABLE " + a4.getOldName() + " RENAME TO " + a4.getName() + ";");
                        b42 = (GenTable)this.genTableMapper.get(a4);
                        b42.setOldName(a4.getName());
                        this.genTableMapper.update(b42);
                    }

                    if(!a4.getComments().equals(a4.getOldComments())) {
                        a11.append("alter table " + a4.getName() + " comment \'" + a4.getComments() + "\';");
                        this.genTableService.f("alter table " + a4.getName() + " comment \'" + a4.getComments() + "\';");
                        b42 = (GenTable)this.genTableMapper.get(a4);
                        b42.setOldComments(a4.getComments());
                        b42.setOldGenIdType(a4.getGenIdType());
                        this.genTableMapper.update(b42);
                    }

                    Iterator pk1 = a3.iterator();

                    GenTableColumn b41;
                    String column1;
                    while(pk1.hasNext()) {
                        b41 = (GenTableColumn)pk1.next();
                        column1 = b41.getOldName();
                        if(b41.getDelFlag().equals("1") && this.a3(a4, column1)) {
                            a11.append("alter table " + a4.getName() + " drop " + column1 + ";");
                            this.genTableService.f("alter table " + a4.getName() + " drop " + column1 + ";");
                            this.genTableColumnMapper.delete(b41);
                        }
                    }

                    pk1 = a3.iterator();

                    label260:
                    while(true) {
                        GenTableColumn a13;
                        do {
                            do {
                                do {
                                    if(!pk1.hasNext()) {
                                        pk1 = a3.iterator();

                                        while(pk1.hasNext()) {
                                            b41 = (GenTableColumn)pk1.next();
                                            column1 = b41.getOldName();
                                            c11 = b41.getName();
                                            if(!b41.getDelFlag().equals("1") && column1 == null) {
                                                a11.append("alter table " + a4.getName() + " add " + c11 + " " + b41.getJdbcType() + " comment \'" + b41.getComments() + "\';");
                                                this.genTableService.f("alter table " + a4.getName() + " add " + b41.getName() + " " + b41.getJdbcType() + " comment \'" + b41.getComments() + "\';");
                                                a13 = (GenTableColumn)this.genTableColumnMapper.get(b41.getId());
                                                a13.setOldComments(b41.getComments());
                                                a13.setOldIsPk(b41.getIsPk());
                                                a13.setOldJdbcType(b41.getJdbcType());
                                                a13.setOldName(b41.getName());
                                                this.genTableColumnMapper.update(a13);
                                            }
                                        }

                                        if(a4.getGenIdType() != null && !a4.getGenIdType().equals(a4.getOldGenIdType())) {
                                            pk1 = a3.iterator();

                                            while(pk1.hasNext()) {
                                                b41 = (GenTableColumn)pk1.next();
                                                if(!b41.getDelFlag().equals("1") && b41.getName() != null && b41.getIsPk().equals("1")) {
                                                    if(a4.getGenIdType().equals("2")) {
                                                        column1 = b41.getJdbcType();
                                                        if(!column1.toLowerCase().contains("int") && !column1.toLowerCase().contains("integer")) {
                                                            column1 = "integer";
                                                            b41.setJdbcType(column1);
                                                            c1 = (GenTableColumn)this.genTableColumnMapper.get(b41.getId());
                                                            c1.setJdbcType(column1);
                                                            c1.setOldJdbcType(column1);
                                                            this.genTableColumnMapper.update(c1);
                                                        }

                                                        this.genTableService.f("alter table " + a4.getName() + " change   " + b41.getName() + " " + b41.getName() + " " + column1 + " auto_increment ;");
                                                    } else {
                                                        column1 = b41.getJdbcType();
                                                        if(!column1.toLowerCase().contains("varchar")) {
                                                            column1 = "varchar(64)";
                                                            b41.setJdbcType(column1);
                                                            c1 = (GenTableColumn)this.genTableColumnMapper.get(b41.getId());
                                                            c1.setJdbcType(column1);
                                                            c1.setOldJdbcType(column1);
                                                            this.genTableColumnMapper.update(c1);
                                                        }

                                                        this.genTableService.f("alter table " + a4.getName() + " change   " + b41.getName() + " " + b41.getName() + " " + column1 + " ;");
                                                    }
                                                }
                                            }
                                        }

                                        pk2 = "";
                                        column2 = "";
                                        column = a2.iterator();

                                        while(column.hasNext()) {
                                            c1 = (GenTableColumn)column.next();
                                            if(c1.getIsPk().equals("1")) {
                                                pk2 = pk2 + c1.getName() + ",";
                                            }

                                            if("1".equals(c1.getOldIsPk())) {
                                                column2 = column2 + c1.getName() + ",";
                                            }
                                        }

                                        if(!column2.equals(pk2)) {
                                            a11.append("alter table " + a4.getName() + " drop primary key;");
                                            this.genTableService.f("alter table " + a4.getName() + " drop primary key;");
                                            column = a2.iterator();

                                            while(column.hasNext()) {
                                                c1 = (GenTableColumn)column.next();
                                                if("1".equals(c1.getOldIsPk())) {
                                                    a13 = (GenTableColumn)this.genTableColumnMapper.get(c1.getId());
                                                    a13.setOldIsPk("0");
                                                    this.genTableColumnMapper.update(a13);
                                                }
                                            }

                                            if(pk2.length() > 0) {
                                                a11.append("alter table " + a4.getName() + " add  CONSTRAINT PK_SJ_RESOURCE_CHARGES PRIMARY KEY(" + pk2.substring(0, pk2.length() - 1) + ");");
                                                this.genTableService.f("alter table " + a4.getName() + " add  CONSTRAINT PK_SJ_RESOURCE_CHARGES PRIMARY KEY(" + pk2.substring(0, pk2.length() - 1) + ");");
                                                column = a2.iterator();

                                                while(column.hasNext()) {
                                                    c1 = (GenTableColumn)column.next();
                                                    if("1".equals(c1.getIsPk())) {
                                                        a13 = (GenTableColumn)this.genTableColumnMapper.get(c1.getId());
                                                        a13.setOldIsPk("1");
                                                        this.genTableColumnMapper.update(a13);
                                                    }
                                                }
                                            }
                                        }

                                        j.setMsg("同步数据库表成功!");
                                        break label260;
                                    }

                                    b41 = (GenTableColumn)pk1.next();
                                    column1 = b41.getOldName();
                                    c11 = b41.getName();
                                } while(b41.getDelFlag().equals("1"));
                            } while(column1 == null);
                        } while(c11.equals(column1) && b41.getJdbcType().equals(b41.getOldJdbcType()) && b41.getComments().equals(b41.getOldComments()));

                        c2 = StringUtils.isBlank(b41.getOldName())?b41.getName():b41.getOldName();
                        a11.append("alter table " + a4.getName() + " change  " + column1 + " " + c11 + " " + b41.getJdbcType() + " comment \'" + b41.getComments() + "\';");
                        this.genTableService.f("alter table " + a4.getName() + " change  " + c2 + " " + b41.getName() + " " + b41.getJdbcType() + " comment \'" + b41.getComments() + "\';");
                        a13 = (GenTableColumn)this.genTableColumnMapper.get(b41.getId());
                        a13.setOldComments(b41.getComments());
                        a13.setOldIsPk(b41.getIsPk());
                        a13.setOldJdbcType(b41.getJdbcType());
                        a13.setOldName(b41.getName());
                        this.genTableColumnMapper.update(a13);
                    }
                } else {
                    a11 = new StringBuffer();
                    if(StringUtils.isNotBlank(a4.getOldName())) {
                        a11.append("drop table if exists " + a4.getOldName() + " ;");
                    } else {
                        a11.append("drop table if exists " + a4.getName() + " ;");
                    }

                    this.genTableService.f(a11.toString());
                    b42 = (GenTable)this.genTableMapper.get(a4);
                    b42.setOldName(a4.getName());
                    this.genTableMapper.update(b42);
                    a11 = new StringBuffer();
                    a11.append("create table " + a4.getName() + " (");
                    column2 = "";
                    column = a3.iterator();

                    while(column.hasNext()) {
                        c1 = (GenTableColumn)column.next();
                        if(!c1.getDelFlag().equals("1") && c1.getName() != null) {
                            if(c1.getIsPk().equals("1")) {
                                if(a4.getGenIdType().equals("2")) {
                                    c2 = c1.getJdbcType();
                                    if(!c2.toLowerCase().contains("int") && !c2.toLowerCase().contains("integer")) {
                                        c2 = "integer";
                                        c1.setJdbcType(c2);
                                    }

                                    a11.append("  " + c1.getName() + " " + c2 + " auto_increment  comment \'" + c1.getComments() + "\',");
                                } else {
                                    c2 = c1.getJdbcType();
                                    if(!c2.toLowerCase().contains("varchar")) {
                                        c2 = "varchar(64)";
                                        c1.setJdbcType(c2);
                                    }

                                    a11.append("  " + c1.getName() + " " + c2 + " comment \'" + c1.getComments() + "\',");
                                }

                                column2 = column2 + c1.getName() + ",";
                            } else {
                                a11.append("  " + c1.getName() + " " + c1.getJdbcType() + " comment \'" + c1.getComments() + "\',");
                            }
                        }
                    }

                    a11.append("primary key (" + column2.substring(0, column2.length() - 1) + ") ");
                    a11.append(") comment \'" + a4.getComments() + "\' DEFAULT CHARSET=utf8");
                    this.genTableService.f(a11.toString());
                    j.setMsg("重新建表成功!");
                }
            } else {
                Iterator b421;
                GenTableColumn column21;
                if("oracle".equals(a1)) {
                    a11 = new StringBuffer();

                    try {
                        a11.append("DROP TABLE " + a4.getOldName());
                        this.genTableService.f(a11.toString());
                    } catch (Exception var20) {
                        ;
                    }

                    a11 = new StringBuffer();
                    a11.append("create table " + a4.getName() + " (");
                    pk2 = "";
                    b421 = a2.iterator();

                    while(b421.hasNext()) {
                        column21 = (GenTableColumn)b421.next();
                        c11 = column21.getJdbcType();
                        if(c11.equalsIgnoreCase("integer")) {
                            c11 = "number(10,0)";
                        } else if(c11.equalsIgnoreCase("datetime")) {
                            c11 = "date";
                        } else if(c11.contains("nvarchar(")) {
                            c11 = c11.replace("nvarchar", "nvarchar2");
                        } else if(c11.contains("varchar(")) {
                            c11 = c11.replace("varchar", "varchar2");
                        } else if(c11.equalsIgnoreCase("double")) {
                            c11 = "float(24)";
                        } else if(c11.equalsIgnoreCase("longblob")) {
                            c11 = "blob";
                        } else if(c11.equalsIgnoreCase("longtext")) {
                            c11 = "clob";
                        }

                        if(column21.getIsPk().equals("1")) {
                            a11.append("  " + column21.getName() + " " + c11 + ",");
                            pk2 = pk2 + column21.getName();
                        } else {
                            a11.append("  " + column21.getName() + " " + c11 + ",");
                        }
                    }

                    a11 = new StringBuffer(a11.substring(0, a11.length() - 1) + ")");
                    this.genTableService.f(a11.toString());
                    this.genTableService.f("comment on table " + a4.getName() + " is  \'" + a4.getComments() + "\'");
                    b421 = a2.iterator();

                    while(b421.hasNext()) {
                        column21 = (GenTableColumn)b421.next();
                        this.genTableService.f("comment on column " + a4.getName() + "." + column21.getName() + " is  \'" + column21.getComments() + "\'");
                    }

                    this.genTableService.f("alter table " + a4.getName() + " add constraint PK_" + a4.getName() + "_" + pk2 + " primary key (" + pk2 + ") ");
                } else if("mssql".equals(a1) || "sqlserver".equals(a1)) {
                    a11 = new StringBuffer();
                    a11.append("if exists (select * from sysobjects where id = object_id(N\'[" + a4.getName() + "]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1)  drop table [" + a4.getName() + "]");
                    this.genTableService.f(a11.toString());
                    a11 = new StringBuffer();
                    a11.append("create table " + a4.getName() + " (");
                    pk2 = "";
                    b421 = a2.iterator();

                    while(b421.hasNext()) {
                        column21 = (GenTableColumn)b421.next();
                        if(column21.getIsPk().equals("1")) {
                            a11.append("  " + column21.getName() + " " + column21.getJdbcType() + ",");
                            pk2 = pk2 + column21.getName() + ",";
                        } else {
                            a11.append("  " + column21.getName() + " " + column21.getJdbcType() + ",");
                        }
                    }

                    a11.append("primary key (" + pk2.substring(0, pk2.length() - 1) + ") ");
                    a11.append(")");
                    this.genTableService.f(a11.toString());
                }
            }

            this.genTableService.c(a4);
            j.setSuccess(true);
            return j;
        }
    }

    private boolean a3(GenTable a1, String columnName) {
        List a2 = this.genDataBaseDictMapper.findTableColumnList(a1);
        Iterator var4 = a2.iterator();

        GenTableColumn a3;
        do {
            if(!var4.hasNext()) {
                return false;
            }

            a3 = (GenTableColumn)var4.next();
        } while(columnName == null || !columnName.equals(a3.getName()));

        return true;
    }

    @RequiresPermissions({"gen:genTable:genCode"})
    @RequestMapping({"genCodeForm"})
    public String a2(String tableType, GenScheme a1, Model model, RedirectAttributes redirectAttributes) {
        if(StringUtils.isBlank(a1.getPackageName())) {
            a1.setPackageName("com.jeeplus.modules");
        }

        if(StringUtils.isBlank(a1.getCategory())) {
            if("1".equals(tableType)) {
                a1.setCategory("curd_many");
            } else if("3".equals(tableType)) {
                a1.setCategory("treeTable");
            } else if("4".equals(tableType)) {
                a1.setCategory("leftTreeRightTable");
            } else {
                a1.setCategory("curd");
            }
        }

        GenScheme a3 = this.genSchemeService.b1("gen_table_id", a1.getGenTable().getId());
        if(a3 != null) {
            a1 = a3;
        }

        if(StringUtils.isBlank(a1.getProjectPath())) {
            a1.setProjectPath(Global.getProjectPath());
        }

        model.addAttribute("genScheme", a1);
        model.addAttribute("config", a.a7());
        model.addAttribute("tableList", this.genTableService.a3());
        return "modules/gen/genCodeForm";
    }

    @ResponseBody
    @RequestMapping({"genCode"})
    public AjaxJson a1(GenScheme a3, Model model, RedirectAttributes redirectAttributes) throws Exception {
        AjaxJson j = new AjaxJson();
        String a1 = "";
        a1 = this.genSchemeService.a2(a3);
        j.setSuccess(true);
        j.setMsg(a3.getGenTable().getName() + "代码生成成功<br/>" + a1);
        return j;
    }
}
